package com.yunpuvip.sachet.modular.factory;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.qrcode.QrCodeUtil;
import cn.stylefeng.roses.kernel.model.exception.ServiceException;
import com.microsoft.schemas.office.x2006.encryption.CTKeyEncryptor;
import com.yunpuvip.sachet.modular.core.exception.GunsException;
import com.yunpuvip.sachet.modular.core.exception.GunsExceptionEnum;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

/**
 * @ClassName QrCodeFactory
 * @Description TODO
 * @Autor wushaohong
 * @Date 2019/3/28
 * @Version 1.0
 */
@Component
public class QrCodeFactory {


    /**
     * 根据url生成二维码
     * @param qrcode
     * @return
     */

    /*public  static   byte[]    createQrcode(QrcodeParam qrcode){
        byte[] png = QrCodeUtil.generatePng(qrcode.getUrl(), 300, 300);
        return png;
    }*/

    /**
     * 根据url集合 批量生成二维码对的字节数组
     * @param urlList
     * @param out
     */
  /*  public  static void createQrcodeList(List<QrPageBean> urlList, ZipArchiveOutputStream out){
        ArrayList<byte[]> list=new ArrayList<>();
        if(ObjectUtil.length(urlList)>0){
            urlList.stream().forEach(s -> {
                byte[] png = QrCodeUtil.generatePng(s.getUrl(), 300, 300);
                String fileName= s.getName()+UUID.randomUUID()+".png";
                ArchiveEntry entry = new ZipArchiveEntry(fileName);
                try {
                    out.putArchiveEntry(entry);
                    out.write(png);
                    out.closeArchiveEntry();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                //QrCodeUtil.g
            });

        }
    }*/

}
